package com.wen.project.service.impl;
import java.util.Date;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wen.apicommon.model.entity.InterfaceInfo;
import com.wen.apicommon.service.InnerInterfaceInfoService;

import com.wen.project.common.ErrorCode;
import com.wen.project.exception.BusinessException;
import com.wen.project.service.InterfaceInfoService;
import com.wen.project.mapper.InterfaceInfoMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author wenzhaobo
* @description 针对表【interface_info(接口信息)】的数据库操作Service实现
* @createDate 2024-07-15 22:03:27
*/
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
    implements InterfaceInfoService {

    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {

            if (interfaceInfo == null) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR);
            }

            Long id = interfaceInfo.getId();
            String name = interfaceInfo.getName();
            String description = interfaceInfo.getDescription();
            String url = interfaceInfo.getUrl();
            String requestHeader = interfaceInfo.getRequestHeader();
            String responseHeader = interfaceInfo.getResponseHeader();
            Integer status = interfaceInfo.getStatus();
            String method = interfaceInfo.getMethod();
            Long userId = interfaceInfo.getUserId();
            Date createTime = interfaceInfo.getCreateTime();
            Date updateTime = interfaceInfo.getUpdateTime();
            Integer isDelete = interfaceInfo.getIsDelete();

            // 创建时，所有参数必须非空
            if(add){
                if(StringUtils.isAnyBlank(name)){
                    throw new BusinessException(ErrorCode.PARAMS_ERROR);
                }
            }
            if(StringUtils.isNotBlank(name) && name.length() > 50){
                throw new BusinessException(ErrorCode.PARAMS_ERROR,"名称过长");
            }
        }
    
}




